﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace WebAsbesto.CDC
{
    public partial class CDC_MuestrasAdd_aspx : System.Web.UI.Page
    {
        int Id_CDC;
        int Id_Obra;
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["User"] != "1")
                Response.Redirect("../Login/Login.aspx");
            else if (Session["User"] == "1")
            {
                //PAGE LOAD ACA
                string Consulta = "Select Id_CDC, Id_Obra From CDC Where Id_CDC = (Select max (Id_CDC) AS Id_CDC From CDC)";
                DataSet ds = new DataSet();
                ds = Funciones.Read_DataBase(Consulta);
                
                Id_CDC = Convert.ToInt32(ds.Tables[0].Rows[0]["Id_CDC"]);
                Id_Obra = Convert.ToInt32(ds.Tables[0].Rows[0]["Id_Obra"]);

                if (!IsPostBack)
                {
                    Cargar_Datos(Id_CDC, Id_Obra);
                }
            }
        }

        protected void img_Muestras_Aire_Click(object sender, ImageClickEventArgs e)
        {
            Response.Write("<script>window.open('CDC_MuestrasAddAdd.aspx?Tipo=Aire&Obra=" + Id_Obra + "&CDC=" + Id_CDC + "', 'Muestras Aire', 'toolbar=0', 'width=300', 'height=300');</script>");
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            Response.Write("<script>window.open('CDC_MuestrasAddAdd.aspx?Tipo=Bulk&Obra=" + Id_Obra + "&CDC=" + Id_CDC + "', 'Muestras Aire', 'toolbar=0', 'width=300', 'height=300');</script>");
        }

        protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
        {
            Response.Write("<script>window.open('CDC_MuestrasAddAdd.aspx?Tipo=Superficie&Obra=" + Id_Obra + "&CDC=" + Id_CDC + "', 'Muestras Aire', 'toolbar=0', 'width=300', 'height=300');</script>");
        }

        protected void Cargar_Datos(int Id_CDC, int Id_Obra)
        {
                string Consulta = "Select Nombre From Obras Where Id_Obra =" + Id_Obra;
                DataSet ds = new DataSet();
                ds = Funciones.Read_DataBase(Consulta);

                lbl_Titulo.Text += "Numero: " + Id_CDC + " de la Obra: " + ds.Tables[0].Rows[0]["Nombre"].ToString(); 
        }
    }
}